﻿namespace Sidvall.ExceptionHandling
{
    public class SystemExceptionProvider : IExceptionProvider
    {
        #region Public Members

        #region GetMessage

        public virtual string GetMessage(System.Collections.Generic.IEnumerable<System.Exception> exceptions, string messageSeparator, string sectionSeparator)
        {
            var sb = new System.Text.StringBuilder();
            if (exceptions != null)
            {
                foreach (var exception in exceptions)
                {
                    var item = exception;
                    if (sb.Length > 0)
                        sb.Append(sectionSeparator);
                    sb.Append("Messages:");
                    while (item != null)
                    {
                        sb.Append(messageSeparator);
                        sb.Append(item.Message);
                        item = item.InnerException;
                    }
                    sb.Append(sectionSeparator);
                    sb.Append("StackTrace:");
                    sb.Append(messageSeparator);
                    sb.Append(exception.StackTrace);
                }
            }
            return sb.ToString();
        }

        #endregion

        #region ToString

        public override string ToString()
        {
            return "ExceptionProvider - System";
        }

        #endregion

        #endregion
    }
}
